package com.lire.shop.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Configuration
public class OpenAPIConfig {

    @Bean
    public OpenAPI openAPI() {


        Info info = new Info()
                .title("Tutorial Management API")
                .version("1.0")
                .description("This API exposes to manage tutorials.")
                .contact(
                        new Contact()
                                .email("2557947043c@gmail.com")
                                .name("lire")
                                .url("https://www.lirhyme.com/")
                )
                .license(
                        new License()
                                .name("This is name of License")
                                .url("https://www.google.com/")
                );

        Server server1 = new Server()
                .url("http://localhost:8080/")
                .description("This is a description of Server.");

        Server server2 = new Server()
                .url("http://localhost:80/")
                .description("This is a description of Server.");

        return new OpenAPI()
                .addSecurityItem(new SecurityRequirement().addList("my security"))
                .components(new Components().addSecuritySchemes("my security",
                        new SecurityScheme().name("my security")
                                .type(SecurityScheme.Type.HTTP).scheme("bearer")))
                .info(info)
                .servers(Arrays.asList(server1, server2));
    }
}
